package org.sczfdf.conf;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.json.JSONUtil;
import org.sczfdf.bean.CmdInfo;
import org.sczfdf.constants.Constant;
import org.sczfdf.utils.PropertiesUtil;

import java.util.Arrays;
import java.util.List;

/**
 * @author Created by cgb
 * @date 2023/1/31
 */
public class WatchConf {
    private static final WatchConf WATCH_CONF = new WatchConf();
    public static WatchConf get() {
        return WATCH_CONF;
    }

    private int watchInterval;
    private List<CmdInfo> watchOtherCmdLit;
    private List<String> watchWatchSuffix;

    private WatchConf() {
        String cmdJson = PropertiesUtil.getConf(Constant.WATCH_OTHER_CMD);
        if (JSONUtil.isTypeJSONArray(cmdJson)) {
            watchOtherCmdLit = JSONUtil.toList(cmdJson, CmdInfo.class);
            watchOtherCmdLit = watchOtherCmdLit == null ? ListUtil.empty() : watchOtherCmdLit;
        }

        watchWatchSuffix = Arrays.asList(PropertiesUtil.getConf(Constant.WATCH_WATCH_SUFFIX).split(","));

        watchInterval = Integer.parseInt(PropertiesUtil.getConf(Constant.WATCH_INTERVAL));
    }

    public List<CmdInfo> getWatchOtherCmdLit() {
        return watchOtherCmdLit;
    }

    public void setWatchOtherCmdLit(List<CmdInfo> watchOtherCmdLit) {
        this.watchOtherCmdLit = watchOtherCmdLit;
    }

    public int getWatchInterval() {
        return watchInterval;
    }

    public void setWatchInterval(int watchInterval) {
        this.watchInterval = watchInterval;
    }

    public List<String> getWatchWatchSuffix() {
        return watchWatchSuffix;
    }

    public void setWatchWatchSuffix(List<String> watchWatchSuffix) {
        this.watchWatchSuffix = watchWatchSuffix;
    }
}
